function[class] = mahalanobisClassification(featureVec, meanVecs, covarMats)
% Classifies the given feature vector using the mahalanobis distance.
%
%   INPUT
%   featureVec......The feature vector that shall be classified
%   meanVecs........An array of the mean feature vector of every class.
%   covarMats.......The covariance matrices for every class.
%   OUTPUT
%   class...........the classification for the given vector as the id.
    
    lowest_dist = Inf; %initialize with infinity
   
    for i = 1 : size(meanVecs, 2)
        meanVec = meanVecs(:,i);
        inverseCovarianceMatrix = inv(covarMats(:,:,i));
        mahalDist = (featureVec-meanVec)' * inverseCovarianceMatrix * (featureVec-meanVec);
        if (mahalDist < lowest_dist)
            lowest_dist = mahalDist;
            class = i;
        end
    end
end
